Repository navigation
Report runtime audio processing changes in the audio track features - #1239
Draft
hiroshihorie wants to merge 1 commit into
Draft
hiroshihorie wants to merge 1 commit into
hiroshihorie wants to merge 1 commit into
Conversation
LocalAudioTrack.setAudioProcessingOptions(_:) changes echo cancellation, noise suppression and auto gain control at runtime, but the features sent to the server were still derived from the immutable captureOptions, and LocalTrackPublication only re-sent them on set(track:) and on Krisp delegate changes. The server kept advertising the publish-time features. The track now records the options once WebRTC accepts them (applied or stored), on the RTC executor so concurrent calls are recorded in the order they were applied, and derives its features from them. A rejected call throws before anything is recorded, so it leaves the features unchanged. The publication is notified through a new internal track delegate protocol and re-sends the features when they differ from the last ones sent. A runtime change made before publishing is picked up by the AddTrackRequest and the first feature update. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After a successful
LocalAudioTrack.setAudioProcessingOptions(_:), the audio features the server holds for the track are stale.LocalAudioTrack.features(publishOptions:)was built from the immutablecaptureOptions, andLocalTrackPublication.sendAudioTrackFeatures()only ran onset(track:)and on Krisp delegate changes. So after turning echo cancellation, noise suppression or auto gain control off at runtime, the server kept advertising the publish-timeTF_ECHO_CANCELLATION/TF_NOISE_SUPPRESSION/TF_AUTO_GAIN_CONTROL, and the other way round.Change
Internal only, no public API change.
LocalAudioTrackkeeps the options last accepted bysetAudioProcessingOptions(_:)in aStateSync. They are recorded inside the existingmediaTrack.blockingclosure, right after WebRTC returnsappliedorstored. That runs on the serial RTC executor, so concurrent calls are recorded in the same order WebRTC applied them. A rejected call throws before anything is recorded, so the reported features stay as they were.features(publishOptions:)now derives the processing features from those runtime options, falling back tocaptureOptionsuntil the first successful runtime change.toFeatures()moved fromAudioCaptureOptionstoAudioProcessingOptions(the capture options already project onto it viaaudioProcessing).LocalAudioTrackDelegateInternalprotocol, next toTrackDelegateInternal.LocalTrackPublicationconforms and calls the existingsendAudioTrackFeatures(), which already diffs against the last features sent and skips the send when nothing changed. No new locks, queues or Combine subscriptions.AddTrackRequestand by the feature update that followsset(track:), since both go throughfeatures(publishOptions:).Worth checking
appliedandstoredcount as accepted.storedmeans WebRTC kept the options for the sender to reapply, which matches what the track will run with once it is published.startCapture()still passescaptureOptions.audioProcessingtoAudioManager.startLocalRecording. I left that alone because it changes processing behaviour and not just reporting, but it does mean that a capture restart after a runtime change starts recording with the capture options while the reported features follow the runtime options. Should it use the runtime options as well?MulticastDelegate.notifydelivers asynchronously.Tests
LocalAudioTrackFeaturesTests(unit tests, no server and no audio hardware): the options-to-features mapping; features followcaptureOptionsuntil runtime options are recorded, and publish-option features (TF_NO_DTX) are still merged in; a realsetAudioProcessingOptions(.noProcessing)on an unpublished track returnsappliedorstored, updates the features and notifies the track delegate.PublishTrackTests.runtimeAudioProcessingChangeUpdatesFeatures: it publishes a track, waits until the subscriber sees the three processing features in theTrackInfo, callssetAudioProcessingOptions(.noProcessing), and checks that both the local publication and the subscriber'sTrackInfodrop them. With the notification call temporarily removed, this test fails on both expectations.What was run:
xcodebuild build-for-testing -scheme LiveKitforplatform=macOSand for an iPhone 18 Pro simulator (Xcode 27.2): both succeeded, with no new warnings in the touched files.livekit-server --dev:LocalAudioTrackFeaturesTests,AudioProcessingOptionsTestsand all ofPublishTrackTestspassed (18 tests).LocalAudioTrackFeaturesTestsandAudioProcessingOptionsTestspassed. The e2ePublishTrackTestssuite did not complete on the simulator in my environment. Its existing tests, which this PR does not change, stalled and were restarted the same way as the new one, so the e2e test was verified on macOS only.swiftformat --lint .andswiftlint lint --strictare clean.Not verified
Not run on a physical device. I did not check that the reported features match what the device's audio processing actually does on real hardware; the tests only cover what the SDK records and sends.
🤖 Generated with Claude Code